package cc.magicjson.jpa.datasouce.write.rest;


import cc.magicjson.jpa.datasouce.entity.Users;
import cc.magicjson.jpa.datasouce.write.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users")
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/{id}")
    public List<Users> getUsersById(@PathVariable Long id){
        return userService.findUserById(id);
    }

    @PostMapping("/save")
    public String saveUser(@RequestBody Users users) {
        userService.saveUser(users);
        return "User saved successfully.";
    }
}
